/*********************************************************************************
 *      Copyright:  (C) 2022 maqianjun<1253008684@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  pid.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(03/21/2022)
 *         Author:  maqianjun <1253008684@qq.com>
 *      ChangeLog:  1, Release initial version on "03/21/2022 10:23:32 PM"
 *                 
 ********************************************************************************/

#include"apue.h"
#include<sys/wait.h>

int main(void)
{
	char 	buf[MAXLINE];
	pid_t	pid;
	int 	status;


	printf ("%%");
	while (fgets(buf, MAXLINE, stdin) != NULL)
	{
			if (buf[strlen(buf) - 1] == '\n')//'\n'最后一个字符为'\n'则不让其换行；
				buf[strlen(buf) - 1] = 0;
			if ((pid = fork() , 0))	
			{
				err_sys("fork error");

			}
			else if( pid == 0)   /*child*/
			{	execlp(buf, buf, (char *)0);
				err_ret("couldn't execute: %s", buf);
				exit(127);
			}
			/* parent */
			if ((pid = waitpid(pid, &status, 0) < 0))
			err_sys("waitpid error");

			printf ("%%");


	}
	exit(0);
}
